/* This will contain all business related calls */

package poler.business  
{
	import mx.utils.ObjectUtil;
	
	import poler.control.events.CreateEvent;
	import poler.control.events.DeleteEvent;
	import poler.control.events.Save64Event;
	import poler.control.events.SelectEvent;
	import poler.control.events.UpdateEvent;
	import poler.model.ModelLocator;
	import poler.model.domain.domainView1;
	  
    public class View1Delegate
    {  
       private var _BOview1:domainView1; 
       
        public function View1Delegate()  
        {
        	_BOview1 = ModelLocator.getInstance().dmView1;  
        } 
            
  		public function select():void{
  			var sQuery:String = "SELECT Id, Name, Birthdate, Phone, Department, Title, Contact.Firstname, Contact.Lastname FROM Contact order by Id desc";
			new SelectEvent(sQuery,null,_BOview1._replaceDetails).dispatch();
  		}
  		public function selectImage():void{
			var sQuery:String = "Select i.Id, i.Contact__c, i.Data__c, i.Stack__c from ImageDetail__c i where i.Contact__c = '"+ModelLocator.getInstance().ContactId+"' order by i.Stack__c";
			new SelectEvent(sQuery,null,_BOview1._setBase64String).dispatch();
  		}
  		public function saveData(saveObj:Object):void{
  			var context:Array = _BOview1._toSObjectArray(saveObj);
  			if(saveObj.Id == null){
				new CreateEvent(context,SaveImage).dispatch();
  			}else{
  				new UpdateEvent(context,SaveImage).dispatch();
  			}
  		}
  		public function deleterec(delObj:Object):void{
  			var context:Object = delObj.Id;
  			new DeleteEvent(context,refreshDG).dispatch();
  		}
  		public function SaveImage(e:Object):void{

  			if(_BOview1.arBase64String.length > 0 && e[0].id != null){
				new Save64Event(e[0].id,_BOview1.arBase64String).dispatch();
			}
  			select();
  		}
  		public function refreshDG(e:Object):void{
  			select();
  		}
       // 
    }  
}     